package com.chen.user.system.usersystem.controller;


import com.chen.user.system.usersystem.entity.UserEntity;
import com.chen.user.system.usersystem.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 用户控制层
 * @author :master
 */
@RestController
@RefreshScope
@RequestMapping(value = "/user")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/addUser")
    public String addUser(@RequestBody UserEntity userEntity) {
        try {
            userService.addUser(userEntity);
            return "用户注册成功";
        }catch (Exception e) {
            return e.getMessage();
        }
    }


    @RequestMapping("/updateUser")
    public String updateUser(@RequestBody UserEntity userEntity) {
        try {
            userService.updateUser(userEntity);
            return "用户操作成功";
        }catch (Exception e) {
            return e.getMessage();
        }
    }

    @RequestMapping("/queryUser")
    public List<UserEntity> queryUser() {
        try {
            // Thread.sleep(10000);
            return userService.queryUsers();
        }catch (Exception e) {
            return null;
        }
    }
}
